package com.superyee.commonlib.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.superyee.commonlib.constants.AppConfig;

/**
 * 图片文件
 */
public class AttachFileBean implements Parcelable {

    public int id;
    /**
     * remote路径
     **/
    public String path;
    //本地路径
    @JSONField(serialize = false)
    public String localPath;
    public int width;
    public int height;
    @JSONField(serialize = false)
    public boolean isVideo;
    public int attach_type;
    //标记是否已经上传到七牛,用于本地提交时避免重复上传
    public boolean uploaded;


    public String getFinalPath() {
        if (!TextUtils.isEmpty(path)) {
            return AppConfig.QINIU_URL + "/" + path;
        }
        return localPath;
    }

    public AttachFileBean() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getLocalPath() {
        return localPath;
    }

    public void setLocalPath(String localPath) {
        this.localPath = localPath;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public boolean isVideo() {
        return isVideo;
    }

    public void setVideo(boolean video) {
        isVideo = video;
    }

    public int getAttach_type() {
        return attach_type;
    }

    public void setAttach_type(int attach_type) {
        this.attach_type = attach_type;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.path);
        dest.writeString(this.localPath);
        dest.writeInt(this.width);
        dest.writeInt(this.height);
        dest.writeByte(this.isVideo ? (byte) 1 : (byte) 0);
        dest.writeInt(this.attach_type);
        dest.writeByte(this.uploaded ? (byte) 1 : (byte) 0);
    }

    protected AttachFileBean(Parcel in) {
        this.id = in.readInt();
        this.path = in.readString();
        this.localPath = in.readString();
        this.width = in.readInt();
        this.height = in.readInt();
        this.isVideo = in.readByte() != 0;
        this.attach_type = in.readInt();
        this.uploaded = in.readByte() != 0;
    }

    public static final Creator<AttachFileBean> CREATOR = new Creator<AttachFileBean>() {
        @Override
        public AttachFileBean createFromParcel(Parcel source) {
            return new AttachFileBean(source);
        }

        @Override
        public AttachFileBean[] newArray(int size) {
            return new AttachFileBean[size];
        }
    };
}
